package com.zzu.chat.util;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.zzu.chat.R;
import com.zzu.chat.activity.MainActivity;
import com.zzu.chat.activity.DynamicActivity;
import com.zzu.chat.activity.MessageActivity;
import com.zzu.chat.activity.MeActivity;
import com.zzu.chat.activity.TimeActivity;

/**
 * Created by Yang on 2019/11/3 0003.
 */

public class BottomLayout extends LinearLayout {    //自定义控件类

    public BottomLayout(final Context context, AttributeSet attributeSet){
        super(context,attributeSet);
        LayoutInflater.from(context).inflate( R.layout.bottom,this);

        // 获取布局中的控件
        LinearLayout mainLine = findViewById(R.id.main_line_layout);
        ImageView  mainImage = findViewById(R.id.main_image);
        TextView mainText = findViewById(R.id.main_text);

        LinearLayout messageLine = findViewById(R.id.message_line_layout);
        ImageView messageImage = findViewById(R.id.message_image);
        TextView messageText = findViewById(R.id.message_text);

        LinearLayout dynamicLine = findViewById(R.id.dynamic_line_layout);
        ImageView  dynamicImage = findViewById(R.id.dynamic_image);
        TextView dynamicText = findViewById(R.id.dynamic_text);

        LinearLayout timeLine = findViewById(R.id.time_line_layout);
        ImageView timeImage = findViewById(R.id.time_image);
        TextView timeText = findViewById(R.id.time_text);

        LinearLayout meLine = findViewById(R.id.me_line_layout);
        ImageView meImage = findViewById(R.id.me_image);
        TextView meText = findViewById(R.id.me_text);


        // 对点击事件进行监听
        // 跳转到MainActivity
        mainLine.setOnClickListener(new OnClickListener() {
            @SuppressLint("ResourceAsColor")
            @Override
            public void onClick(View v) {
                MainActivity.actionStart(context);

                mainImage.setImageResource(R.drawable.ic_meet_click);
                mainText.setTextColor(R.color.bottomClick);

                messageImage.setImageResource(R.drawable.ic_message);
                messageText.setTextColor(R.color.bottomTextColor);

                dynamicImage.setImageResource(R.drawable.ic_dynamic);
                dynamicText.setTextColor(R.color.bottomTextColor);

                timeImage.setImageResource(R.drawable.ic_time);
                timeText.setTextColor(R.color.bottomTextColor);

                meImage.setImageResource(R.drawable.ic_me);
                meText.setTextColor(R.color.bottomTextColor);


            }
        });

        // 消息
        messageLine.setOnClickListener(new View.OnClickListener(){
            @SuppressLint("ResourceAsColor")
            @Override
            public void onClick(View v) {

                MessageActivity.actionStart(context);


                mainImage.setImageResource(R.drawable.ic_meet);
                mainText.setTextColor(R.color.bottomTextColor);

                messageImage.setImageResource(R.drawable.ic_message_click);
                messageText.setTextColor(R.color.bottomClick);

                dynamicImage.setImageResource(R.drawable.ic_dynamic);
                dynamicText.setTextColor(R.color.bottomTextColor);

                timeImage.setImageResource(R.drawable.ic_time);
                timeText.setTextColor(R.color.bottomTextColor);

                meImage.setImageResource(R.drawable.ic_me);
                meText.setTextColor(R.color.bottomTextColor);

            }
        });

        // 跳转到动态
        dynamicLine.setOnClickListener(new OnClickListener() {
            @SuppressLint("ResourceAsColor")
            @Override
            public void onClick(View v) {
                DynamicActivity.actionStart(context);

                mainImage.setImageResource(R.drawable.ic_meet);
                mainText.setTextColor(R.color.bottomTextColor);

                messageImage.setImageResource(R.drawable.ic_message);
                messageText.setTextColor(R.color.bottomTextColor);

                dynamicImage.setImageResource(R.drawable.ic_dynamic_click);
                dynamicText.setTextColor(R.color.bottomClick);

                timeImage.setImageResource(R.drawable.ic_time);
                timeText.setTextColor(R.color.bottomTextColor);

                meImage.setImageResource(R.drawable.ic_me);
                meText.setTextColor(R.color.bottomTextColor);
            }
        });

        // 跳转到时间页面
        timeLine.setOnClickListener(new OnClickListener() {
            @SuppressLint("ResourceAsColor")
            @Override
            public void onClick(View v) {
                TimeActivity.actionStart(context);

                mainImage.setImageResource(R.drawable.ic_meet);
                mainText.setTextColor(R.color.bottomTextColor);

                messageImage.setImageResource(R.drawable.ic_message);
                messageText.setTextColor(R.color.bottomTextColor);

                dynamicImage.setImageResource(R.drawable.ic_dynamic);
                dynamicText.setTextColor(R.color.bottomTextColor);

                timeImage.setImageResource(R.drawable.ic_time_click);
                timeText.setTextColor(R.color.bottomClick);

                meImage.setImageResource(R.drawable.ic_me);
                meText.setTextColor(R.color.bottomTextColor);
            }
        });
        // 跳转到MeActivity
        meLine.setOnClickListener(new OnClickListener() {
            @SuppressLint("ResourceAsColor")
            @Override
            public void onClick(View v) {
                MeActivity.actionStart(context);

                mainImage.setImageResource(R.drawable.ic_meet_click);
                mainText.setTextColor(R.color.bottomClick);

                messageImage.setImageResource(R.drawable.ic_message);
                messageText.setTextColor(R.color.bottomTextColor);

                dynamicImage.setImageResource(R.drawable.ic_dynamic);
                dynamicText.setTextColor(R.color.bottomTextColor);

                timeImage.setImageResource(R.drawable.ic_time);
                timeText.setTextColor(R.color.bottomTextColor);

                meImage.setImageResource(R.drawable.ic_me_click);
                meText.setTextColor(R.color.bottomClick);
            }
        });
    }
}
